#! /bin/sh

bindir="@CMAKE_INSTALL_PREFIX@/@BINDIR@"
libdir="@CMAKE_INSTALL_PREFIX@/@LIBDIR@"

LIBPATH="$libdir/simspark:$libdir/rcssserver3d"
if [ x"$LIBPATH" != x ] ; then
    if [ x"$LD_LIBRARY_PATH" = x ] ; then
        LD_LIBRARY_PATH=$LIBPATH
    else
        LD_LIBRARY_PATH=$LIBPATH:$LD_LIBRARY_PATH
    fi
    export LD_LIBRARY_PATH
fi

#--------------------------------------------------
# option
#

SERV="$bindir/rcssserver3d"
if [ ! -f $SERV ]; then
    echo "Error: $SERV does not exist!"
    echo ""
    exit 1
fi

MON="$bindir/rcssmonitor3d"
if [ ! -f $MON ]; then
    echo "Error: $MON does not exist!"
    echo ""
    exit 1
fi

#--------------------------------------------------
# set handler
#

trap kill_server INT

#--------------------------------------------------
# start server
#

$SERV &
PID=$!

#--------------------------------------------------
# kill server
#
kill_server()
{
    kill -s INT $PID
    echo ""
    exit 0
}

#--------------------------------------------------
# start monitor
#

sleep 2

$MON

kill_server
